home *** CD-ROM | disk | FTP | other *** search
- #pragma option v
- #include "hc05j1.h"
- #include "general.h"
-
- /* define the global variables */
-
- int hrs,mts,sec;
- int count;
- int corr1,corr2,corr3; /* used to correct the time errors */
-
- main(void)
- {
- corr1=corr2=corr3=0; /* time corrections */
- TCST.RT0=0; /* 57.3 ms cop timer */
- TCST.RT1=0; /* 8.192 ms RTI */
- TCST.RTIE=1; /* Turn on the RTI */
- TCST.RTIF=0; /* Reset interruput */
- TCST.TOF=0; /* flags */
- CLI(); /* turn on interrupt */
-
- FOREVER
- {
- if(sec==60) /* do clock things each minute */
- {
- sec=0;
- if(++mts==60)
- {
- mts=0;
- if(++hrs==13)
- hrs=1;
- }
- }
- WAIT(); /* wait here to save the energy */
- }
- }
-
- void __TIMER(void) /* routine executed every RTI (8.192 ms) */
- {
- TCST.TOF=0; /* reset the interrupt */
- TCST.RTIF=0; /* flags */
-
- if (++count==122)
- {
- sec++; /* increment seconds */
- if(++corr1==14) /* To correct for 8.192 ms per tick */
- {
- corr1=0; /* run 122 ticks per second for 13 */
- if(++corr2==80) /* seconds, and 123 for the 14th second */
- { /* With this algorithm there are 14.000128 */
- corr2=0; /* actual seconds per 14 indicated. Then run */
- if(++corr3==4)
- {
- count=1;
- corr3==0;
- }
- else
- count=0;/* 79 of these cycles followed by one cycle of */
- } /* 14 seconds with 122 ticks per second. The */
- else /* elapsed time for this cycle is 1120.002048 */
- count=(-1); /* seconds for and indicated time of 1120 */
- } /* seconds. Repeat this cycle 4 times and on*/
- else /* the last cycle drop one tick makes the */
- count=0; /* indicate and elapsed time exactly 4480 seconds.*/
- }
- }
-
-